﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;

namespace CSharpLearningWeb
{
    public partial class Async : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Timer1_Tick(object sender, EventArgs e)
        {
            IAsyncResult async = null;
            SqlDataReader reader = null;

            var Cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString);

            var Cmd = Cnn.CreateCommand();
            Cmd.CommandText = "Select * From TvShows";
            Cmd.CommandType = CommandType.Text;

            Cnn.Open();
            async = Cmd.BeginExecuteReader();
            while (!async.IsCompleted)
            {
                Response.Output.WriteLine("Waiting...");
            }
            reader = Cmd.EndExecuteReader(async);
            while (reader.Read())
            {
                Response.Output.WriteLine(reader["Name"].ToString());
            }
            Cnn.Close();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            IAsyncResult async = null;
            SqlDataReader reader = null;

            var Cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString);

            var Cmd = Cnn.CreateCommand();
            Cmd.CommandText = "Select * From TvShows";
            Cmd.CommandType = CommandType.Text;

            Cnn.Open();
            async = Cmd.BeginExecuteReader();
            while (!async.IsCompleted)
            {
                Response.Output.WriteLine("Waiting...");
            }
            reader = Cmd.EndExecuteReader(async);
            while (reader.Read())
            {
                Response.Output.WriteLine(reader["Name"].ToString());
            }
            Cnn.Close();
        }
    }
}